﻿using System;
using System.Net;
using System.Threading.Tasks;

namespace Inovout.Net
{
    public class HttpClient
    {
        public Uri ServerUri { get; private set; }
        public HttpClient(Uri serverUri)
        {
            ServerUri = serverUri;
        }
        internal HttpRequest CreateRequest()
        {
            return new HttpRequest((HttpWebRequest)WebRequest.Create(ServerUri));
        }

        internal IAsyncResult Send(HttpRequest request,IHttpResponseParser httpResponseParser)
        {
            HttpResponse response = new HttpResponse(request, httpResponseParser);
            var asyncResult = request.HttpWebRequest.BeginGetResponse(new AsyncCallback(response.ResponseCallback), null);
            httpResponseParser.AsyncWaitHandle = asyncResult.AsyncWaitHandle;
            return asyncResult;
        }

    }
}
